-- directory?
dir = "config\\lua\\Greedy\\PickitRevolution\\"

-- you probably don't want to change anything in this file besides dir!

-- action consts (best to leave these alone!)
aPICK  = 1
aIDENT = 2
aSELL  = 3
aDUMP  = 4

-- itemActions List
itemActions = {}

-- load common functions (so we don't have to worry about people taking it out of includes)
loadfile(dir .. "common.lua")()

-- load includes
loadfile(dir .. "includes.lua")()

-- main gateway func
function processItem(item, action)
	local i, r

if item.flags.isRuneword -- probably not the right item member - should stop RWs from being sold.
   then return false
end

	for i = 1, #itemActions do
		r = itemActions[i](item, action)
		if r ~= nil and r ~= false then
			return r
		end
	end

	return false
end

-- gateway helper funcs

-- see: dir .. "readme.txt" for information regarding itemLists

--- using: itemLists
function getItemIndex(item, itemList)
	local i, j, element

	for i = 1, #itemList do
		element = itemList[i][1]
		-- added type checks to avoid requiring specific itemList ordering
		-- these checks need to stay (unless someone can come up with a better method)
		-- note: unique lists support itemcode lists, perhaps they shouldn't? lmk what you think
		if  type(element) == "string" and item.baseItem.code == element then
			return i
		elseif type(element) == "table" then
			for j = 1, #itemList[i][1] do
				element = itemList[i][1][j]
				if type(element) == "string" and item.baseItem.code == element then
					return i
				end
			end
		end
	end
	
	-- added this check so unique lists don't get ran again
	-- (I don't see any practical applications for using ItemKind with uniques)
	if item.quality == ItemQuality.Unique then return 0 end
	
	-- added ItemKind support (for whites/others)
	for i = 1, #itemList do
		-- note: ItemKind.x is seen as a number
		-- have not tried replacing ItemKind.x with the literal index in enum ItemKind
		element = itemList[i][1]
		if type(element) == "number" and item.baseItem.baseType.Type == element then
			return i
		end
	end

	return 0
end

--- using: getItemIndex()
function processItemList(item, action, itemList)
	local i = getItemIndex(item, itemList)
		
	if i == 0 then
		return false
	elseif action == aPICK and (itemList[i][4] == nil or itemList[i][4](item)) then
		return itemList[i][2]
	elseif action == aIDENT then
		return (itemList[i][3] == true)
	elseif action == aSELL then
		return (itemList[i][4] ~= nil and not itemList[i][4](item))
	elseif action == aDUMP then
		return (itemList[i][4] ~= nil and not itemList[i][4](item))
	end
	
	return false
end

--[[ STILL NEEDS TESTING!
	eventually I would like to use this (or something similar) in unique lists
	in order to swap the ident portion of an element
	ex: if you want to keep eth titans unid but also want to check stats of noneth
	havn't had time to properly test it yet, but *think* it *should* work
	]]
--- using: getItemIndex()
function changeItemIdent(item, ident, itemList)
	local i = getItemIndex(item, itemList)
	
	itemList[i][3] = ident
end


--- see also: dir .. "common.lua"
